﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WebComponents.Data;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using System.IO;

public partial class Install_Default : System.Web.UI.Page {
  protected void Page_Load(object sender, EventArgs e) {
    //System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath("~/install/data.sql"));

    //string SQLscript = file.OpenText().ReadToEnd();

    //System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("\r\n\\s*GO");
    //SQLscript = Regex.Split(SQLscript + "\n", @"^\s*GO\s*$", RegexOptions.IgnoreCase | RegexOptions.Multiline);
    //SQLscript = SQLscript.Replace("/r/nGO", ";");
    //SQLscript = regex.Replace(SQLscript, ";");
    //Optional to Replace Comments with empty string

    //SQLscript = Regex.Replace(SQLscript, "([/*][*]).*([*][/])", "");

    //Optional to Replace Chain of spaces with one Space

    //SQLscript = Regex.Replace(SQLscript, "\\s{2,}", " ");
    SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["conString"].ConnectionString);
    SqlCommand sqlCommand = new SqlCommand("update core_menus set isactive=1 where menuid=29", cnn);

    sqlCommand.Connection.Open();

    sqlCommand.ExecuteNonQuery();

    sqlCommand.Connection.Close();

    //using (SqlCommand sc = new SqlCommand("", new SqlConnection(ConfigurationManager.ConnectionStrings["conString"].ConnectionString))) {
    //  sc.CommandType = System.Data.CommandType.Text;
    //  sc.Connection.Open();

    //  try {
    //    string allCommands;
    //    using (StreamReader sr = File.OpenText(Server.MapPath("~/install/data.sql"))) {
    //      allCommands = sr.ReadToEnd();
    //    }
    //    string[] commands = allCommands.Split(new string[] { "\nGO" }, StringSplitOptions.RemoveEmptyEntries);
    //    foreach (string command in commands) {
    //      sc.CommandText = command;
    //      sc.ExecuteNonQuery();
    //      //Console.WriteLine("{0} rows effected.", sc.ExecuteNonQuery());
    //    }
    //  } finally {
    //    sc.Connection.Close();
    //  }
    //}

  }
}
